package com.atguigu.controller;

import com.atguigu.utils.JWTUtils;
import com.auth0.jwt.interfaces.DecodedJWT;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("test")
@Slf4j
public class TestController {

    /*验证token*/
    @PostMapping("/verify")
    public Map<String,Object> verify(HttpServletRequest request){
        HashMap<String, Object> map = new HashMap<>();
        // 处理自己的业务逻辑
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtils.verifyToken(token);
        log.info("token中的userId : [{}]",decodedJWT.getClaim("userId").asString());
        log.info("token中的username : [{}]",decodedJWT.getClaim("username").asString());
        map.put("msg","验证通过");
        map.put("status",true);
        return map;
    }
}
